<?php
//xóa hết sp mà chưa có mặt trong đơn hàng
include_once '../include/common.php';
$core = new core();
var_dump("bat dau xoa san pham");
$list_product = $core->db->get_results("SELECT * FROM zen_product WHERE product_id > 3982");
if ($list_product) {
    foreach($list_product as $product) {
        $extra_photo = $product->extra_photo;
        $product_id = $product->product_id;
        $list_extra_photo = explode(',',$extra_photo);
        $new_extra_photo = array();
        $product_code = $core->convert_string_friendly($product->product_code);

        foreach($list_extra_photo as $photo){
            if(strpos($photo,$product_code) !== false){
                $new_extra_photo[] = $photo;
            }
        }

        $new_extra_photo = implode(',', $new_extra_photo);
        if($new_extra_photo ==''){
            $new_extra_photo = $product->main_photo;
        }

        $core->db->query("UPDATE zen_product SET
                extra_photo='".$new_extra_photo."' WHERE product_id=$product_id");
        var_dump('cap nhat thanh cong');
    }
} else {
    echo json_encode(array('type' => 1, 'msg' => "Xóa sản phẩm không thành công!"));
    die;
}